﻿@{
    Bundle("jquery_validate");
}
           
@foreach(var i in Model.Comments)
{
    <fieldset class="groupbox">
        <legend>
            <ul class="bar inlinebar">
                <li><a class="confirm" href="@Url.Action(Loc.Act("Delete").Ctrl("Comment").NoArea().Set(new
                {
                    operation = "DeleteCatalogItemComment", 
                    returnUrl = Request.RawUrl,
                    id = JDM.Int32(i.EntityID)
                }))">x</a></li>
            </ul>
            @Svc.DateTime((DateTime)JDM.DateTime(i.CreatedOn))
        </legend>
        <section>
            <script type="text/javascript">
                jQuery(document).ready(function () {
                    jQuery('@ID("#form_{0}", JDM.Int32(i.EntityID))').validate({
                        rules: {
                            title: {
                                required: true
                            },
                            text: {
                                required: true
                            }
                        }
                    });
                });
            </script>
            <form id="@ID("form_{0}", JDM.Int32(i.EntityID))" action="@Url.Action(Loc.Act("Update").Ctrl("Comment").NoArea())" method="post">
                <input type="hidden" name="operation" value="UpdateCatalogItemComment" />
                <input type="hidden" name="returnUrl" value="@Request.RawUrl" />
                <input type="hidden" name="flags" value="None" />
                <table>
                    <tr>
                        <td>
                            <label>#</label>
                        </td>
                        <td>
                            <input type="text" readonly name="id" value="@JDM.Int32(i.EntityID)" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @if(i.Account != null)
                            {
                                <a href="@Url.Action(Loc.Act("Edit").Ctrl("Account").Area("Membership").Set(new
                                {
                                    id = JDM.Int32(i.Account.EntityID)
                                }))" class="ui-icon ui-icon-extlink"></a>
                            }
                            <label>@T(Res.Name("Account"))</label>
                        </td>
                        <td>
                            <input type="text" value="@(i.Account != null ? JDM.String(i.Account.Email) : String.Empty)" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Title"))</label>
                        </td>
                        <td>
                            <input type="text" name="title" value="@JDM.String(i.Title)" maxlength="1000" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Text"))</label>
                        </td>
                        <td>
                            <textarea name="text" maxlength="4000">@JDM.String(i.Text)</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.In("API").Of("Enum").Of("CatalogItemCommentFlags").Name("Active"))</label>
                        </td>
                        <td>
                            <input type="checkbox" name="flags" value="Active" @(JDM.HasFlags(i.Flags, "Active") ? "checked" : String.Empty) />
                        </td>
                    </tr>
                </table>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                </ul>
            </form>
        </section>
    </fieldset>
}
<fieldset class="groupbox">
    <section>
        <script type="text/javascript">
            jQuery(document).ready(function () {
                jQuery('@ID("#form")').validate({
                    rules: {
                        title: {
                            required: true
                        },
                        text: {
                            required: true
                        }
                    }
                });
                jQuery('@ID("#txt_account")').autocomplete({
                    source: function (request, response) {
                        jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Account").Area("Membership")))', request, response);
                    },
                    minLength: 3,
                    select: function (event, ui) {
                        jQuery('@ID("#hidden_account")').val(ui.item.id);
                    }
                });
            });
        </script>
        <form id="@ID("form")" action="@Url.Action(Loc.Act("Create").Ctrl("Comment").NoArea())" method="post">
            <input type="hidden" name="holderID" value="@Model.EntityID" />
            <input type="hidden" name="operation" value="CreateCatalogItemComment" />
            <input type="hidden" name="returnUrl" value="@Request.RawUrl" />
            <input type="hidden" name="flags" value="None" />
            <table>
                <tr>
                    <td>
                        <label>@T(Res.Name("Account"))</label>
                    </td>
                    <td>
                        <input id="@ID("hidden_account")" type="hidden" name="accountID" value="0" />
                        <input id="@ID("txt_account")" type="text" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Title"))</label>
                    </td>
                    <td>
                        <input type="text" name="title" maxlength="1000" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Text"))</label>
                    </td>
                    <td>
                        <textarea name="text" maxlength="4000"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.In("API").Of("Enum").Of("CatalogItemCommentFlags").Name("Active"))</label>
                    </td>
                    <td>
                        <input type="checkbox" name="flags" value="Active" />
                    </td>
                </tr>
            </table>
            <ul class="bar toolbar">
                <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
            </ul>
        </form>
    </section>
</fieldset>